/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package group2assignone.model;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Natalie
 */
public class AirportTable extends AbstractTableModel {

    private String[] columnNames = {"Airport Location", "Airport Tax"};
    private String[][] data = null;

    public AirportTable(ArrayList<Airport> airportList) {
        int row = 0;
        if (!(airportList == null))
        {
            data = new String[airportList.size()][columnNames.length];

            for (Airport ap : airportList)
            {
                String airportLoc = ap.getAirportLoc();
                double airportTax = ap.getAirportTax();
                
                int column = 0;
                data[row][column] = airportLoc;
                column++;
                data[row][column] = ""+airportTax;
                row++;
            }

        }

    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        if(data != null){
        return data.length;
        }
        else{
            return 0;
        }
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public String getValueAt(int row, int col) {
        return data[row][col];
    }

    /*
     * JTable uses this method to determine the default renderer/
     * editor for each cell.  If we didn't implement this method,
     * then the last column would contain text ("true"/"false"),
     * rather than a check box.
     */
    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    @Override
    public boolean isCellEditable(int row, int col) {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        return false;
    }

    /*
     * Don't need to implement this method unless your table's
     * data can change.
     */
    public void setValueAt(String value, int row, int col) {
        data[row][col] = value;
        fireTableCellUpdated(row, col);
    }

}
